﻿using DevExpress.XtraGrid.Views.Base;

namespace Lonntec.DevClient
{
    using DevExpress.XtraEditors;
    using DevExpress.XtraEditors.Controls;
    using DevExpress.XtraEditors.DXErrorProvider;
    using DevExpress.XtraEditors.Repository;
    using DevExpress.XtraGrid;
    using DevExpress.XtraGrid.Columns;
    using DevExpress.XtraGrid.Views.Grid;
    using Furious.Common;
    using Furious.Data;
    using Lonntec.Business;
    using Lonntec.DevClient.Properties;
    using Lonntec.UI;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Windows.Forms;

    public class AccountManagerForm : DocumentBase
    {
        private readonly IgnoreCaseDictionary<ErpAccountInfo> accountInfos = new IgnoreCaseDictionary<ErpAccountInfo>();
        private ComboBoxEdit cbbFNumber;
        private GridColumn colFErpID;
        private GridColumn colFName;
        private GridColumn colFName1;
        private GridColumn colFName2;
        private GridColumn colFNumber;
        private IContainer components;
        private SmartColumn dsColumnFName;
        private SmartColumn dsColumnFNumber;
        private SmartColumn dsColumnFOwnerID;
        private SmartColumn dsColumnFRowID;
        private SmartSource dsErp;
        private SmartSource dsMaster;
        private DevExpress.XtraEditors.DXErrorProvider.DXErrorProvider dxErrorProvider1;
        private GridLookUpEdit gridLookUpEdit1;
        private GridView gridLookUpEdit1View;
        private GridControl gridMaster;
        private GridView gvMaster;
        private Label label1;
        private Label label2;
        private Label label3;
        private RepositoryItemGridLookUpEdit repositoryItemGridLookUpEdit1;
        private GridView repositoryItemGridLookUpEdit1View;
        private SmartColumn smartColumn1;
        private SmartColumn smartColumn2;
        private SmartColumn smartColumn3;
        private TextEdit txtFName;

        public AccountManagerForm()
        {
            this.InitializeComponent();
        }

        private void CbbFNumberSelectedValueChanged(object sender, EventArgs e)
        {
            if (base.EditMode && this.accountInfos.ContainsKey(this.cbbFNumber.Text))
            {
                ErpAccountInfo info = this.accountInfos[this.cbbFNumber.Text];
                base.MasterSource.CurrentRowView["FName"] = info.AccountName;
                this.txtFName.EditValue = info.AccountName;
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private DataTable GetSettingTable(ISingleDbAccess dbAccess, string tableName)
        {
            DataTable table = dbAccess.ExecuteTable("select * from {0}", new object[] { tableName });
            table.TableName = tableName;
            return table;
        }

        private void InitializeComponent()
        {
            this.components = new Container();
            this.dsMaster = new SmartSource();
            this.dsColumnFRowID = new SmartColumn();
            this.dsColumnFOwnerID = new SmartColumn();
            this.dsColumnFNumber = new SmartColumn();
            this.dsColumnFName = new SmartColumn();
            this.gridMaster = new GridControl();
            this.gvMaster = new GridView();
            this.colFErpID = new GridColumn();
            this.repositoryItemGridLookUpEdit1 = new RepositoryItemGridLookUpEdit();
            this.dsErp = new SmartSource();
            this.smartColumn1 = new SmartColumn();
            this.smartColumn2 = new SmartColumn();
            this.smartColumn3 = new SmartColumn();
            this.repositoryItemGridLookUpEdit1View = new GridView();
            this.colFNumber = new GridColumn();
            this.colFName = new GridColumn();
            this.colFName1 = new GridColumn();
            this.label1 = new Label();
            this.gridLookUpEdit1 = new GridLookUpEdit();
            this.gridLookUpEdit1View = new GridView();
            this.colFName2 = new GridColumn();
            this.label2 = new Label();
            this.cbbFNumber = new ComboBoxEdit();
            this.label3 = new Label();
            this.txtFName = new TextEdit();
            this.dxErrorProvider1 = new DevExpress.XtraEditors.DXErrorProvider.DXErrorProvider(this.components);
            base.TabControl.BeginInit();
            base.TabControl.SuspendLayout();
            base.plTop.BeginInit();
            base.plTop.SuspendLayout();
            base.tabPageGrid.SuspendLayout();
            base.tabPageCard.SuspendLayout();
            base.plCard.BeginInit();
            base.plCard.SuspendLayout();
            base.plGrid.BeginInit();
            base.plGrid.SuspendLayout();
            ((ISupportInitialize) this.dsMaster).BeginInit();
            this.gridMaster.BeginInit();
            this.gvMaster.BeginInit();
            this.repositoryItemGridLookUpEdit1.BeginInit();
            ((ISupportInitialize) this.dsErp).BeginInit();
            this.repositoryItemGridLookUpEdit1View.BeginInit();
            this.gridLookUpEdit1.Properties.BeginInit();
            this.gridLookUpEdit1View.BeginInit();
            this.cbbFNumber.Properties.BeginInit();
            this.txtFName.Properties.BeginInit();
            ((ISupportInitialize) this.dxErrorProvider1).BeginInit();
            base.SuspendLayout();
            base.tabPageCard.Appearance.PageClient.BackColor = Color.White;
            base.tabPageCard.Appearance.PageClient.Options.UseBackColor = true;
            base.plCard.Controls.Add(this.txtFName);
            base.plCard.Controls.Add(this.label3);
            base.plCard.Controls.Add(this.cbbFNumber);
            base.plCard.Controls.Add(this.label2);
            base.plCard.Controls.Add(this.gridLookUpEdit1);
            base.plCard.Controls.Add(this.label1);
            base.plGrid.Controls.Add(this.gridMaster);
            this.dsMaster.Columns.AddRange(new SmartColumn[] { this.dsColumnFRowID, this.dsColumnFOwnerID, this.dsColumnFNumber, this.dsColumnFName });
            this.dsMaster.Key = "dsMaster";
            this.dsMaster.OwnerControl = null;
            this.dsMaster.ParentSource = null;
            this.dsMaster.PrimaryColumns.Add(this.dsColumnFRowID);
            this.dsMaster.SourceScript = new SqlScript("Select FRowID,FErpID,FNumber,FName\r\nFrom T_ErpInstance", null, null);
            this.dsMaster.TableCaption = null;
            this.dsMaster.TableName = "T_ErpInstance";
            this.dsColumnFRowID.FieldAlias = null;
            this.dsColumnFRowID.FieldName = "FRowID";
            this.dsColumnFRowID.FullName = "FRowID";
            this.dsColumnFOwnerID.AllowEmpty = false;
            this.dsColumnFOwnerID.FieldAlias = null;
            this.dsColumnFOwnerID.FieldCaption = "帐套版本";
            this.dsColumnFOwnerID.FieldName = "FErpID";
            this.dsColumnFOwnerID.FullName = "FErpID";
            this.dsColumnFNumber.AllowEmpty = false;
            this.dsColumnFNumber.AllowExists = false;
            this.dsColumnFNumber.FieldAlias = null;
            this.dsColumnFNumber.FieldCaption = "帐套编码";
            this.dsColumnFNumber.FieldName = "FNumber";
            this.dsColumnFNumber.FullName = "FNumber";
            this.dsColumnFName.AllowEmpty = false;
            this.dsColumnFName.AllowExists = false;
            this.dsColumnFName.FieldAlias = null;
            this.dsColumnFName.FieldCaption = "帐套名称";
            this.dsColumnFName.FieldName = "FName";
            this.dsColumnFName.FullName = "FName";
            this.gridMaster.DataSource = this.dsMaster;
            this.gridMaster.Dock = DockStyle.Fill;
            this.gridMaster.Location = new Point(0, 0);
            this.gridMaster.MainView = this.gvMaster;
            this.gridMaster.Name = "gridMaster";
            this.gridMaster.RepositoryItems.AddRange(new RepositoryItem[] { this.repositoryItemGridLookUpEdit1 });
            this.gridMaster.Size = new Size(0x2c9, 0x18d);
            this.gridMaster.TabIndex = 0;
            this.gridMaster.ViewCollection.AddRange(new BaseView[] { this.gvMaster });
            this.gvMaster.Columns.AddRange(new GridColumn[] { this.colFErpID, this.colFNumber, this.colFName });
            this.gvMaster.GridControl = this.gridMaster;
            this.gvMaster.Name = "gvMaster";
            this.gvMaster.OptionsView.ShowGroupPanel = false;
            this.colFErpID.ColumnEdit = this.repositoryItemGridLookUpEdit1;
            this.colFErpID.FieldName = "FErpID";
            this.colFErpID.Name = "colFErpID";
            this.colFErpID.OptionsColumn.ReadOnly = true;
            this.colFErpID.Visible = true;
            this.colFErpID.VisibleIndex = 0;
            this.repositoryItemGridLookUpEdit1.AutoHeight = false;
            this.repositoryItemGridLookUpEdit1.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Combo) });
            this.repositoryItemGridLookUpEdit1.DataSource = this.dsErp;
            this.repositoryItemGridLookUpEdit1.DisplayMember = "FName";
            this.repositoryItemGridLookUpEdit1.Name = "repositoryItemGridLookUpEdit1";
            this.repositoryItemGridLookUpEdit1.ValueMember = "FRowID";
            this.repositoryItemGridLookUpEdit1.View = this.repositoryItemGridLookUpEdit1View;
            this.dsErp.Columns.AddRange(new SmartColumn[] { this.smartColumn1, this.smartColumn2, this.smartColumn3 });
            this.dsErp.IsOffline = true;
            this.dsErp.Key = "smartSource1";
            this.dsErp.OwnerControl = null;
            this.dsErp.ParentSource = null;
            this.dsErp.PrimaryColumns.Add(this.smartColumn1);
            this.dsErp.SourceScript = new SqlScript("Select FRowID,FAdapterID,FName From V_Erp", null, null);
            this.dsErp.TableCaption = null;
            this.dsErp.TableName = "V_Erp";
            this.smartColumn1.FieldAlias = null;
            this.smartColumn1.FieldName = "FRowID";
            this.smartColumn1.FullName = "FRowID";
            this.smartColumn2.FieldAlias = null;
            this.smartColumn2.FieldName = "FAdapterID";
            this.smartColumn2.FullName = "FAdapterID";
            this.smartColumn3.FieldAlias = null;
            this.smartColumn3.FieldCaption = "K/3 明细版本";
            this.smartColumn3.FieldName = "FName";
            this.smartColumn3.FullName = "FName";
            this.repositoryItemGridLookUpEdit1View.FocusRectStyle = DrawFocusRectStyle.RowFocus;
            this.repositoryItemGridLookUpEdit1View.Name = "repositoryItemGridLookUpEdit1View";
            this.repositoryItemGridLookUpEdit1View.OptionsSelection.EnableAppearanceFocusedCell = false;
            this.repositoryItemGridLookUpEdit1View.OptionsView.ShowGroupPanel = false;
            this.colFNumber.FieldName = "FNumber";
            this.colFNumber.Name = "colFNumber";
            this.colFNumber.OptionsColumn.ReadOnly = true;
            this.colFNumber.Visible = true;
            this.colFNumber.VisibleIndex = 1;
            this.colFName.FieldName = "FName";
            this.colFName.Name = "colFName";
            this.colFName.OptionsColumn.ReadOnly = true;
            this.colFName.Visible = true;
            this.colFName.VisibleIndex = 2;
            this.colFName1.FieldName = "FName";
            this.colFName1.Name = "colFName1";
            this.colFName1.Visible = true;
            this.colFName1.VisibleIndex = 0;
            this.label1.AutoSize = true;
            this.label1.Location = new Point(0x15, 0x1b);
            this.label1.Name = "label1";
            this.label1.Size = new Size(0x37, 14);
            this.label1.TabIndex = 0;
            this.label1.Text = "帐套版本";
            this.gridLookUpEdit1.DataBindings.Add(new Binding("EditValue", this.dsMaster, "FErpID", true));
            this.gridLookUpEdit1.Location = new Point(0x52, 0x18);
            this.gridLookUpEdit1.Name = "gridLookUpEdit1";
            this.gridLookUpEdit1.Properties.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Combo) });
            this.gridLookUpEdit1.Properties.DataSource = this.dsErp;
            this.gridLookUpEdit1.Properties.DisplayMember = "FName";
            this.gridLookUpEdit1.Properties.NullText = "";
            this.gridLookUpEdit1.Properties.ValueMember = "FRowID";
            this.gridLookUpEdit1.Properties.View = this.gridLookUpEdit1View;
            this.gridLookUpEdit1.Size = new Size(0x143, 0x15);
            this.gridLookUpEdit1.TabIndex = 1;
            this.gridLookUpEdit1View.Columns.AddRange(new GridColumn[] { this.colFName2 });
            this.gridLookUpEdit1View.FocusRectStyle = DrawFocusRectStyle.RowFocus;
            this.gridLookUpEdit1View.Name = "gridLookUpEdit1View";
            this.gridLookUpEdit1View.OptionsSelection.EnableAppearanceFocusedCell = false;
            this.gridLookUpEdit1View.OptionsView.ShowGroupPanel = false;
            this.colFName2.FieldName = "FName";
            this.colFName2.Name = "colFName2";
            this.colFName2.Visible = true;
            this.colFName2.VisibleIndex = 0;
            this.label2.AutoSize = true;
            this.label2.Location = new Point(0x15, 0x39);
            this.label2.Name = "label2";
            this.label2.Size = new Size(0x37, 14);
            this.label2.TabIndex = 2;
            this.label2.Text = "帐套编号";
            this.cbbFNumber.DataBindings.Add(new Binding("EditValue", this.dsMaster, "FNumber", true));
            this.cbbFNumber.Location = new Point(0x52, 0x36);
            this.cbbFNumber.Name = "cbbFNumber";
            this.cbbFNumber.Properties.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Combo) });
            this.cbbFNumber.Properties.TextEditStyle = TextEditStyles.DisableTextEditor;
            this.cbbFNumber.Size = new Size(0x143, 0x15);
            this.cbbFNumber.TabIndex = 3;
            this.cbbFNumber.SelectedValueChanged += new EventHandler(this.CbbFNumberSelectedValueChanged);
            this.label3.AutoSize = true;
            this.label3.Location = new Point(0x15, 0x55);
            this.label3.Name = "label3";
            this.label3.Size = new Size(0x37, 14);
            this.label3.TabIndex = 4;
            this.label3.Text = "帐套名称";
            this.txtFName.DataBindings.Add(new Binding("EditValue", this.dsMaster, "FName", true));
            this.txtFName.Location = new Point(0x52, 0x52);
            this.txtFName.Name = "txtFName";
            this.txtFName.Size = new Size(0x143, 0x15);
            this.txtFName.TabIndex = 5;
            this.dxErrorProvider1.ContainerControl = this;
            this.dxErrorProvider1.DataSource = this.dsMaster;
            base.AutoScaleDimensions = new SizeF(7f, 14f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.ClientSize = new Size(0x2cb, 0x1c6);
            base.Name = "AccountManagerForm";
            this.Text = "AccountManagerForm";
            base.TabControl.EndInit();
            base.TabControl.ResumeLayout(false);
            base.plTop.EndInit();
            base.plTop.ResumeLayout(false);
            base.tabPageGrid.ResumeLayout(false);
            base.tabPageCard.ResumeLayout(false);
            base.plCard.EndInit();
            base.plCard.ResumeLayout(false);
            base.plCard.PerformLayout();
            base.plGrid.EndInit();
            base.plGrid.ResumeLayout(false);
            ((ISupportInitialize) this.dsMaster).EndInit();
            this.gridMaster.EndInit();
            this.gvMaster.EndInit();
            this.repositoryItemGridLookUpEdit1.EndInit();
            ((ISupportInitialize) this.dsErp).EndInit();
            this.repositoryItemGridLookUpEdit1View.EndInit();
            this.gridLookUpEdit1.Properties.EndInit();
            this.gridLookUpEdit1View.EndInit();
            this.cbbFNumber.Properties.EndInit();
            this.txtFName.Properties.EndInit();
            ((ISupportInitialize) this.dxErrorProvider1).EndInit();
            base.ResumeLayout(false);
        }

        public override bool OnCanUseAction(ActionInfo actionInfo)
        {
            string str;
            bool flag = base.OnCanUseAction(actionInfo);
            if (((str = actionInfo.Key) == null) || ((!(str == "Initialization") && !(str == "Export")) && !(str == "Import")))
            {
                return flag;
            }
            return (!base.EditMode && (base.MasterSource.CurrentRowView != null));
        }

        private void OnExport(object sender, ActionEventArgs e)
        {
            try
            {
                IMiddleAdapter adapter = base.ProxyFactory.ResolveProxy<IMiddleAdapter>();
                string serviceKey = this.dsMaster.CurrentRowView["FNumber"].ToString();
                adapter.InitializeAccountDbAccess(this.dsMaster.CurrentRowView["FNumber"].ToString());
                ISingleDbAccess dbAccess = base.ProxyFactory.ResolveProxy<ISingleDbAccess>(serviceKey);
                DataSet set = new DataSet("SUF_For_K3");
                set.Tables.Add(this.GetSettingTable(dbAccess, "t_SUF_GlobalSetting"));
                set.Tables.Add(this.GetSettingTable(dbAccess, "t_SUF_SubMessage"));
                set.Tables.Add(this.GetSettingTable(dbAccess, "t_SUF_BarcodeParam"));
                set.Tables.Add(this.GetSettingTable(dbAccess, "t_SUF_BarcodeParamDefaultValue"));
                set.Tables.Add(this.GetSettingTable(dbAccess, "t_SUF_BarcodeParamReadDetailField"));
                set.Tables.Add(this.GetSettingTable(dbAccess, "t_SUF_BarcodeParamReadList"));
                set.Tables.Add(this.GetSettingTable(dbAccess, "t_SUF_BarcodeParamReadListDisp"));
                set.Tables.Add(this.GetSettingTable(dbAccess, "t_SUF_BarcodeParamReadListOrder"));
                FileDialog dialog = new SaveFileDialog();
                dialog.Title = "生成帐套配置文件";
                dialog.DefaultExt = "*.xml";
                dialog.FileName = "SUFConfig.xml";
                dialog.Filter = "帐套配置文件 (*.xml)|*.xml";
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    set.WriteXml(dialog.FileName);
                    LtMessageBox.MessageInfo("导出帐套配置成功！", new object[0]);
                }
            }
            catch (Exception exception)
            {
                LtMessageBox.MessageError(exception.Message, new object[0]);
                base.Logger.Error(exception);
            }
        }

        private void OnImport(object sender, ActionEventArgs e)
        {
            try
            {
                IMiddleAdapter adapter = base.ProxyFactory.ResolveProxy<IMiddleAdapter>();
                string serviceKey = this.dsMaster.CurrentRowView["FNumber"].ToString();
                adapter.InitializeAccountDbAccess(this.dsMaster.CurrentRowView["FNumber"].ToString());
                ISingleDbAccess dbAccess = base.ProxyFactory.ResolveProxy<ISingleDbAccess>(serviceKey);
                DataSet set = new DataSet("SUF_For_K3");
                FileDialog dialog = new OpenFileDialog();
                dialog.Title = "打开帐套配置文件";
                dialog.DefaultExt = "*.xml";
                dialog.FileName = "SUFConfig.xml";
                dialog.Filter = "帐套配置文件 (*.xml)|*.xml";
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    set.ReadXml(dialog.FileName);
                    UpdateCollection tableCollection = new UpdateCollection();
                    this.WriteTable(set, dbAccess, "t_SUF_GlobalSetting", tableCollection);
                    this.WriteTable(set, dbAccess, "t_SUF_SubMessage", tableCollection);
                    this.WriteTable(set, dbAccess, "t_SUF_BarcodeParam", tableCollection);
                    this.WriteTable(set, dbAccess, "t_SUF_BarcodeParamDefaultValue", tableCollection);
                    this.WriteTable(set, dbAccess, "t_SUF_BarcodeParamReadDetailField", tableCollection);
                    this.WriteTable(set, dbAccess, "t_SUF_BarcodeParamReadList", tableCollection);
                    this.WriteTable(set, dbAccess, "t_SUF_BarcodeParamReadListDisp", tableCollection);
                    this.WriteTable(set, dbAccess, "t_SUF_BarcodeParamReadListOrder", tableCollection);
                    dbAccess.SaveAndUpdate(tableCollection);
                    LtMessageBox.MessageInfo("导入帐套配置成功！", new object[0]);
                }
            }
            catch (Exception exception)
            {
                LtMessageBox.MessageError(exception.Message, new object[0]);
                base.Logger.Error(exception);
            }
        }

        protected override void OnInitializationActionGroups(List<ActionInfoGroup> actionGroups)
        {
            base.OnInitializationActionGroups(actionGroups);
            ActionInfoGroup group2 = new ActionInfoGroup();
            group2.Add(new ActionInfo("Initialization", "初始化账套", Resources.Common_Run, Shortcut.None, true));
            group2.Add(new ActionInfo("Export", "导出帐套配置", Resources.Simg_Export, Shortcut.None, true));
            group2.Add(new ActionInfo("Import", "导入帐套配置", Resources.Simg_Import, Shortcut.None, true));
            ActionInfoGroup item = group2;
            actionGroups.Insert(actionGroups.Count - 1, item);
        }

        protected override void OnInitializationActionHandlers()
        {
            base.OnInitializationActionHandlers();
            base.RegisterActionHandler("Initialization", new ActionHandler(this.OnInitializationMetadata));
            base.RegisterActionHandler("Export", new ActionHandler(this.OnExport));
            base.RegisterActionHandler("Import", new ActionHandler(this.OnImport));
        }

        protected override void OnInitializationDataGrids()
        {
            base.OnInitializationDataGrids();
            base.MasterGridView = this.gvMaster;
        }

        protected override void OnInitializationDataSources()
        {
            base.OnInitializationDataSources();
            base.MasterSource = this.dsMaster;
            base.MasterSource.DbAccess = base.ProxyFactory.ResolveProxy<ISingleDbAccess>();
            this.dsErp.DbAccess = base.MasterSource.DbAccess;
            this.dsErp.ReloadRecords();
            base.MasterSource.ReloadRecords();
        }

        private void OnInitializationMetadata(object sender, ActionEventArgs e)
        {
            Cursor cursor = base.ContainerForm.Cursor;
            try
            {
                base.ContainerForm.Cursor = Cursors.WaitCursor;
                if (LtMessageBox.MessageQuestion("您确定要初始化账套 {0} 吗？", new object[] { base.MasterSource.CurrentRowView["FName"] }))
                {
                    LtMessageBox.MessageInfo("数据库账套初如化可能需要较长时间，点击确定后开始！", new object[0]);
                    base.ProxyFactory.ResolveProxy<ILonntecService>().InitialiationAccountDataBase(base.MasterSource.CurrentRowView["FNumber"].ToString());
                    LtMessageBox.MessageInfo("初始化账套完成！", new object[0]);
                }
            }
            finally
            {
                base.ContainerForm.Cursor = cursor;
            }
        }

        public override void OnInitializationRegisterSearchFields()
        {
            base.OnInitializationRegisterSearchFields();
            base.RegisterQuickSearchFields(new string[] { "FNumber", "FName" });
        }

        protected override void OnMasterTableNewRow(object sender, DataTableNewRowEventArgs e)
        {
            base.OnMasterTableNewRow(sender, e);
            e.Row["FRowID"] = Guid.NewGuid();
        }

        public override void OnUpdateEditorStatus(Lonntec.UI.UpdateStatus updateStatus, bool editModeValue, BaseEdit editor)
        {
            base.OnUpdateEditorStatus(updateStatus, editModeValue, editor);
            if ((editor == this.cbbFNumber) && (updateStatus == Lonntec.UI.UpdateStatus.OnInitialization))
            {
                foreach (ErpAccountInfo info in base.ProxyFactory.ResolveProxy<IMiddleAdapter>().GetAllErpAccountsInSystem())
                {
                    this.accountInfos.Add(info.AccountId, info);
                    this.cbbFNumber.Properties.Items.Add(info.AccountId);
                }
            }
        }

        private void WriteTable(DataSet set, ISingleDbAccess dbAccess, string tableName, UpdateCollection tableCollection)
        {
            try
            {
                DataTable table = dbAccess.ExecuteTable("Select * From {0}", new object[] { tableName });
                while (table.DefaultView.Count > 0)
                {
                    table.DefaultView[0].Delete();
                }
                if (set.Tables.Contains(tableName))
                {
                    DataTable table2 = set.Tables[tableName];
                    foreach (DataRowView view in table2.DefaultView)
                    {
                        DataRowView view2 = table.DefaultView.AddNew();
                        foreach (DataColumn column in table.Columns)
                        {
                            if (table2.Columns[column.ColumnName] != null)
                            {
                                view2[column.ColumnName] = view[column.ColumnName];
                            }
                        }
                        view2.EndEdit();
                    }
                    tableCollection.Tables.Add(new TableInfo(table, tableName));
                }
            }
            catch (Exception exception)
            {
                base.Logger.Error(tableName);
                base.Logger.Error(exception);
            }
        }
    }
}

